package cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.floorlevels;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.floorlevels.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.floorlevels.FloorLevelsDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.floorlevels.FloorLevelsConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.floorlevels.FloorLevelsService;

@Tag(name = "管理后台 - 楼号管理")
@RestController
@RequestMapping("/fengdong.smartelderly/floor-levels")
@Validated
public class FloorLevelsController {

    @Resource
    private FloorLevelsService floorLevelsService;

    @PostMapping("/create")
    @Operation(summary = "创建楼号管理")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:create')")
    public CommonResult<Long> createFloorLevels(@Valid @RequestBody FloorLevelsCreateReqVO createReqVO) {
        return success(floorLevelsService.createFloorLevels(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新楼号管理")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:update')")
    public CommonResult<Boolean> updateFloorLevels(@Valid @RequestBody FloorLevelsUpdateReqVO updateReqVO) {
        floorLevelsService.updateFloorLevels(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除楼号管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:delete')")
    public CommonResult<Boolean> deleteFloorLevels(@RequestParam("id") Long id) {
        floorLevelsService.deleteFloorLevels(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "根据id获取详细信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:query')")
    public CommonResult<FloorLevelsRespVO> getFloorLevels(@RequestParam("id") Long id) {
        FloorLevelsDO floorLevels = floorLevelsService.getFloorLevels(id);
        return success(FloorLevelsConvert.INSTANCE.convert(floorLevels));
    }
    @GetMapping("/getFloor")
    @Operation(summary = "获得所有楼号")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:queryfloor')")
    public CommonResult<List<FloorLevelsRespVO>> getFloor(@RequestParam(value = "id", defaultValue = "0") Long id) {
        List<FloorLevelsDO> list = floorLevelsService.getFloors(id);
        return success(FloorLevelsConvert.INSTANCE.convertList(list));
    }
    @GetMapping("/list")
    @Operation(summary = "获得楼号管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:query')")
    public CommonResult<List<FloorLevelsRespVO>> getFloorLevelsList(@RequestParam("ids") Collection<Long> ids) {
        List<FloorLevelsDO> list = floorLevelsService.getFloorLevelsList(ids);
        return success(FloorLevelsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/listAll")
    @Operation(summary = "获得所有楼号管理")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:queryAll')")
    public CommonResult<List<FloorLevelsRespVO>> getFloorLevelsList(@Valid FloorLevelsExportReqVO exportReqVO) {
        List<FloorLevelsDO> list = floorLevelsService.getDiseaseLabelLisAll(exportReqVO);
        return success(FloorLevelsConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得楼号管理分页")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:query')")
    public CommonResult<PageResult<FloorLevelsRespVO>> getFloorLevelsPage(@Valid FloorLevelsPageReqVO pageVO) {
        PageResult<FloorLevelsDO> pageResult = floorLevelsService.getFloorLevelsPage(pageVO);
        return success(FloorLevelsConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出楼号管理 Excel")
    @PreAuthorize("@ss.hasPermission('fengdong.smartelderly:floor-levels:export')")
    @OperateLog(type = EXPORT)
    public void exportFloorLevelsExcel(@Valid FloorLevelsExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<FloorLevelsDO> list = floorLevelsService.getFloorLevelsList(exportReqVO);
        // 导出 Excel
        List<FloorLevelsExcelVO> datas = FloorLevelsConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "楼号管理.xls", "数据", FloorLevelsExcelVO.class, datas);
    }

}
